﻿namespace NKernel.Core.Tests
{
	using System;
	using System.Reflection;
	using NUnit.Framework;
	using NKernel.Core.Provider;
	using NKernel.Core.Impl;
	using System.Collections.Generic;
	using log4net.Config;

	[TestFixture]
	public class TestWindsorProvider
	{
		[TestFixtureSetUp]
		public void Initialise()
		{
			XmlConfigurator.Configure(new System.IO.FileInfo("log4net.config"));
		}
		
		[Test]
		public void TestAssembleComponents()
		{
			IKernelProvider windsorProvider = new WindsorProvider();
			IList<IComponentObject> componentList = windsorProvider.AssembleComponents(new List<ComponentDescriptor>(), new MockKernel());
			Assert.AreEqual(0, componentList.Count);
			
			componentList = windsorProvider.AssembleComponents(GetComponentDescriptorList(), new MockKernel());
			Assert.AreEqual(1, componentList.Count);
		}
		
		private static IList<ComponentDescriptor> GetComponentDescriptorList()
		{
			Assembly assembly = Assembly.GetAssembly(typeof(IKernel));
			
			IList<ComponentDescriptor> componentDescriptors = new List<ComponentDescriptor>();
			ComponentDescriptor descriptor = new ComponentDescriptor("TestComponent", 
			                                                         "NKernel.Core.Tests.IGenericReflection`1[System.String]",
			                                                         "NKernel.Core.Tests.GenericRelectionInstance",
			                                                         "TestAssembly",
			                                                         Assembly.GetExecutingAssembly());
			componentDescriptors.Add(descriptor);
			
			return componentDescriptors;	
		}
	}
	
    public interface IGenericReflection<T>
    {
        #region Methods

        T Create();

        #endregion Methods
    }

    public class GenericRelectionInstance : IGenericReflection<string>
    {
        #region Methods

        public string Create()
        {
            Console.WriteLine("Hello Reflection");

            return "Good Creation";
        }

        #endregion Methods
    }
    
	public class MockKernel : IKernel
	{
		public KernelResult Cleanup()
		{
			throw new NotImplementedException();
		}
		
		public IList<IComponentObject> GetComponents()
		{
			throw new NotImplementedException();
		}
		
		public T GetInstance<T>()
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Init()
		{
			throw new NotImplementedException();
		}
		
		public void InitPriorityList(string[] priorityComponents)
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Load(string[] componentLocations)
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Load()
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Manage()
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Manage(string[] componentLocations)
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Start()
		{
			throw new NotImplementedException();
		}
		
		public KernelResult Stop()
		{
			throw new NotImplementedException();
		}
	}
}
